import org.junit.Test;

public class work10 {
    //实现trim方法
    @Test
    public  void test1(){
        String str = "   java Android   ";
        String newStr = trim(str);
        System.out.println(newStr);
    }

    private String trim(String str) {
        if (str == null || str.equals("")) {
            return "";
        }
        int startIndex = 0;
        int endIndex = str.length() - 1;
        while ((startIndex <= endIndex) && (str.charAt(startIndex) == ' ')) {
            startIndex++;
        }
        while ((startIndex <= endIndex) && (str.charAt(endIndex) == ' ')) {
            endIndex--;
        }
        return str.substring(startIndex,endIndex + 1);
    }

    @Test
    public void test2(){
        String str = "I Love Java！";
        System.out.println(str.toLowerCase());
        System.out.println(str.toUpperCase());
        String newStr = toLowerCase(str);
        System.out.println(newStr);
    }

    private String toLowerCase(String str){
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++) {
            if (array[i] >= 'A' && array[i] <= 'Z'){
                array[i] = (char)(array[i] + 32);
            }
        }
        return  new String(array);
    }
}


